package com.wb.creational.factory;

/**
 * 使用抽象工厂模式解决实际问题
 *
 * @author 魏彪
 */
public class AbstractFactoryTest01 {
    public static void main(String[] args) {
        JavaCourseFactory factory = new JavaCourseFactory();
        factory.createVideo().record();
        factory.createNote().edit();

        PythonCourseFactory pythonCourseFactory = new PythonCourseFactory();
        pythonCourseFactory.createVideo().record();
        pythonCourseFactory.createNote().edit();
    }
}

// 抽象工厂
abstract class CourseFactory {

    public void init() {
        System.out.println("初始化基础数据");
    }

    protected abstract INote createNote();

    protected abstract IVideo createVideo();
}

interface IVideo {
    void record();
}

interface INote {
    void edit();
}

// 创建Java产品族的具体工厂
class JavaCourseFactory extends CourseFactory {
    @Override
    protected INote createNote() {
        super.init();
        return new JavaNote();
    }

    @Override
    protected IVideo createVideo() {
        super.init();
        return new JavaVideo();
    }
}

class PythonCourseFactory extends CourseFactory {
    @Override
    protected INote createNote() {
        super.init();
        return new PythonNote();
    }

    @Override
    protected IVideo createVideo() {
        super.init();
        return new PythonVideo();
    }
}

// 创建Java产品族
class JavaVideo implements IVideo {

    @Override
    public void record() {
        System.out.println("录制Java视频");
    }
}

// 扩展产品等级Java课堂笔记JavaNote类
class JavaNote implements INote {

    @Override
    public void edit() {
        System.out.println("编写Java笔记");
    }
}

class PythonVideo implements IVideo {

    @Override
    public void record() {
        System.out.println("录制Python视频");
    }
}

// 扩展产品等级Python课堂笔记PythonNote类
class PythonNote implements INote {

    @Override
    public void edit() {
        System.out.println("编写Python笔记");
    }
}
